
#include "RibbonCategory.hpp"
#include "RibbonPannel.hpp"

namespace NSRibbon {

	RibbonCategory::RibbonCategory(QWidget* p) :
		QWidget(p) {
		m_layout = new QHBoxLayout;
		m_layout->setSpacing(2);
		m_layout->setContentsMargins(0, 0, 0, 0);
		m_layout->addStretch(1);
		setLayout(m_layout);
	}

	RibbonCategory::~RibbonCategory() {


	}


	RibbonPannel* RibbonCategory::addPannel(QString name) {
		if (m_pannels.contains(name)) {
			return dynamic_cast<RibbonPannel*>(m_pannels.value(name));
		}
		RibbonPannel* pannel = new RibbonPannel(this);
		int index = m_pannels.count() + m_sep_num;
		pannel->setPannelName(name);
		m_pannels.insert(name, pannel);

		m_layout->insertWidget(index, pannel);
		addSeparator();

		return pannel;
	}


	void RibbonCategory::addSeparator() {
		QFrame* _sep = new QFrame(this);
		_sep->setFrameShape(QFrame::VLine);
		_sep->setFrameShadow(QFrame::Plain);
		_sep->setLineWidth(1);
		_sep->setStyleSheet("color: #4F4F4F;");
		int index = m_pannels.count() + m_sep_num;

		m_layout->insertWidget(index, _sep);
		m_sep_num++;
	}

}